package com.bitter.storage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bitter.storage.domain.StorageVo;
import com.bitter.storage.mapper.StorageMapper;
import com.bitter.storage.service.IStorageService;

import feign.Param;

/**
 * 
 * @author thomashe
 *
 */
@RestController
@RequestMapping("/storage")
public class StorageController {

	@Autowired
	StorageMapper storageMapper;

	@Autowired
	IStorageService iStorageService;

	@RequestMapping("/update")
	public String update(StorageVo storage) {
		StorageVo storageOrg = storageMapper.selectById(1); // 查询原先的库存数
		storage.setTotal((storageOrg.getTotal() - 5));// 减5个库存
		storage.setId(1);
		storageMapper.updateById(storage);
		return "Operation inventory updated successfully.";
	}

	@RequestMapping("/get")
	public String get(@Param("id") int id) {
		StorageVo storageOrg = storageMapper.selectById(id); // 查询原先的库存数
		return "现有的库存数为：" + storageOrg.getTotal();
	}

	@RequestMapping("/decrease")
	public String decrease(@RequestParam("productId") Long productId, @RequestParam("total") Integer total) {
		iStorageService.decrease(productId, total);
		return "successfully.";
	}

}
